function a=heap_adjust(a,n,len)
% heap_adjust
v = a(n);
m=2*n;
while m<=len,
    if(m<len && a(m)<a(m+1))
        m =m+1;
    end
    if (v > a(m))
        break;
    end
    
    a(n)=a(m);    
    n=m;
    m= m*2;
end
a(n)=v;    

